package com.ruoyi.pay.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pay.domain.WxPayLog;
import com.ruoyi.pay.service.IWxPayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 微信用户支付记录Controller
 *
 * @author jiang
 * @date 2024-10-27
 */
@RestController
@RequestMapping("/order/payLog")
public class WxPayLogController extends BaseController
{
    @Autowired
    private IWxPayLogService wxPayLogService;

    /**
     * 查询微信用户支付记录列表
     */
    @PreAuthorize("@ss.hasPermi('order:payLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxPayLog wxPayLog)
    {
        startPage();
        List<WxPayLog> list = wxPayLogService.selectWxPayLogList(wxPayLog);
        return getDataTable(list);
    }

    /**
     * 导出微信用户支付记录列表
     */
    @PreAuthorize("@ss.hasPermi('order:payLog:export')")
    @Log(title = "微信用户支付记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxPayLog wxPayLog)
    {
        List<WxPayLog> list = wxPayLogService.selectWxPayLogList(wxPayLog);
        ExcelUtil<WxPayLog> util = new ExcelUtil<WxPayLog>(WxPayLog.class);
        util.exportExcel(response, list, "微信用户支付记录数据");
    }

    /**
     * 获取微信用户支付记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:payLog:query')")
    @GetMapping(value = "/{uuid}")
    public AjaxResult getInfo(@PathVariable("uuid") String uuid)
    {
        return success(wxPayLogService.selectWxPayLogByUuid(uuid));
    }

    /**
     * 新增微信用户支付记录
     */
    @PreAuthorize("@ss.hasPermi('order:payLog:add')")
    @Log(title = "微信用户支付记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxPayLog wxPayLog)
    {
        return toAjax(wxPayLogService.insertWxPayLog(wxPayLog));
    }

    /**
     * 修改微信用户支付记录
     */
    @PreAuthorize("@ss.hasPermi('order:payLog:edit')")
    @Log(title = "微信用户支付记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxPayLog wxPayLog)
    {
        return toAjax(wxPayLogService.updateWxPayLog(wxPayLog));
    }

    /**
     * 删除微信用户支付记录
     */
    @PreAuthorize("@ss.hasPermi('order:payLog:remove')")
    @Log(title = "微信用户支付记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uuids}")
    public AjaxResult remove(@PathVariable String[] uuids)
    {
        return toAjax(wxPayLogService.deleteWxPayLogByUuids(uuids));
    }
}
